package com.bsy.common.manager

import android.view.View
import androidx.fragment.app.FragmentActivity
import com.bsy.common.dialog.ConfirmBottomDialog
import com.bsy.common.dialog.MessageDialog
import com.bsy.common.dialog.listener.ToastDialog


class DialogManager {
    companion object {
        val instance = DialogManager()
    }

    /**
     * 中间确认弹框
     */
    fun showBaseConfirmDialog(
        activity: FragmentActivity,
        title: String,
        content: String,
        cancelBtnText: String = "取消",
        confirmBtnText: String = "确定",
        isHideCancel: Boolean = false,
        onConfirmListener: View.OnClickListener? = null,
        onCancelListener: View.OnClickListener? = null,
    ) {
        MessageDialog.Builder(activity).setTitle(title)
            .setMessage(content)
            .setCancel(cancelBtnText)
            .setConfirm(confirmBtnText)
            .setonCancelListener(onCancelListener)
            .setonConfirmListener(onConfirmListener)
            .setHideCancel(isHideCancel)
            .create().show()
    }

    /**
     * 底部确认弹框
     */
    fun showBaseBottomConfirmDialog(
        activity: FragmentActivity,
        title: String,
        content: String,
        cancelBtnText: String = "取消",
        confirmBtnText: String = "确定",
        isHideCancel: Boolean = false,
        onConfirmListener: View.OnClickListener? = null
    ) {
        ConfirmBottomDialog.Builder(activity).setTitle(title)
            .setMessage(content)
            .setCancel(cancelBtnText)
            .setConfirm(confirmBtnText)
            .setonCancelListener { it?.dismiss() }
            .setonConfirmListener(onConfirmListener)
            .setHideCancel(isHideCancel)
            .create().show()
    }

    fun showToast(activity: FragmentActivity, r: Runnable) {
        ToastDialog.Builder(activity, r)
            .create().show()
    }
}